﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace Hallenberg.Core
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2240:ImplementISerializableCorrectly"), Serializable]
    public class ValidationException : Exception
    {
        Dictionary<string, List<string>> m_ValidationErrors = new Dictionary<string, List<string>>();

        public ValidationException()
        {
        }

        public ValidationException(string message)
            : base(message)
        {
        }

        public ValidationException(string message, Exception inner)
            : base(message, inner)
        {
        }

        protected ValidationException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
        }

        public void AddValidationError(string field, string message)
        {
            if (!m_ValidationErrors.ContainsKey(field))
            {
                m_ValidationErrors.Add(field, new List<string>());
            }

            m_ValidationErrors[field].Add(message);
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
        public Dictionary<string, List<string>> ValidationErrors
        {
            get
            {
                return m_ValidationErrors;
            }
        }
    }
}